package ast;

import java.io.PrintStream;
import java.util.Map;
import java.util.Scanner;
import java.util.Stack;

public class IntConstExpr extends Expr {
    public final Long ival;

    public IntConstExpr(Long i, Location loc) {
        super(loc);
        ival = i;
    }

    public void print(PrintStream ps) {
        ps.print(ival);
    }

    // interpret: return the value of this integer constant
    public AbstractValue evaluate(Stack<Map<String, AbstractValue>> state, Scanner scanner) throws Exception {
        // if ival = 0, return AbstractValue.ZeroInt; if ival > 0, return AbstractValue.PosInt; if ival < 0, return AbstractValue.NegInt
        if (ival == 0) {
            return AbstractValue.ZeroInt;
        } else if (ival > 0) {
            return AbstractValue.PosInt;
        } else {
            return AbstractValue.NegInt;
        }
    }
}
